<?php
include_once '/var/www/html/new/com.inc.php';
include_once '/var/www/html/new/d/meituan/MT.class.php';
$meituan = new Meituan();
$txt=file_get_contents('php://input');
$meituan->logfile($txt,"poiproduct");
$arr = json_decode($txt,true);
$partnerId  = $arr['partnerId'];  //第三方的ID
$method = $arr['body']['method']; //请求方式page:分页;multi:支持单个
if($method == 'multi'){//单个产品查询
	$sel = "select * from uu_qunar_use where supplierIdentity=".$partnerId;
	$GLOBALS['le']->query($sel);
	if($GLOBALS['le']->fetch_assoc()){
		$partnerPoiId = $arr['body']['partnerPoiId']; //景点ID	
		$totalSize = count($partnerPoiId);
		$get_product = $meituan->catch_poi_product($partnerId,$partnerPoiId,$totalSize);
		exit($get_product);
	}	
}elseif($method == 'page'){ //分页查询
	$currentPage = $arr['body']['currentPage']; //当前页数
	$pageSize = $arr['body']['pageSize']; //每页记录数
	$begin = ($currentPage-1)*$pageSize;//计算分页数
	$sel_total = "select count(id) as count from uu_qunar_use  where supplierIdentity='$partnerId'";
	$GLOBALS['le']->query($sel_total);
	$row=$GLOBALS['le']->fetch_assoc();
	$totalSize = $row['count'];
	
	$sel_tids = "select tid_aid from uu_qunar_use where supplierIdentity='$partnerId' and DockingMode=1 limit $begin ,$pageSize";
	$GLOBALS['le']->query($sel_tids);
	$data = array();
	while($row1=$GLOBALS['le']->fetch_assoc()){ 
		$data[] = $row1;
	}
	// print_r($data);exit;
	if($data){
		$partnerDealId  = array();
		foreach($data as $k=>$v){
			foreach($v as $a){
				$alid = explode("|",$a);
				$partnerDealId[] = $alid[1];
			}
		}
		$partnerDealIds = array_values(array_unique($partnerDealId));
		$get_product = $meituan->catch_poi_product($partnerId,$partnerDealIds,$totalSize); 
		exit($get_product);
	}else{
		exit ('{"code":300,"describe":"数据为空,请票付通后台绑定已分销产品","partnerId":"'.$partnerId.'"}');
	}
	
}elseif($method == 'increment'){ //增量查询
	exit('{"code":300,"describe":"未开发增量获取","partnerId":"'.$partnerId.'"}');
}else{//未知方法
	exit('{"code":300,"describe":"请求方式有误","partnerId":"'.$partnerId.'"}');
}

/*
$txt= '{
  "partnerId": 1055,
  "body": {
    "method": "page",
    "currentPage": 1,
    "pageSize": 10,
    "partnerPoiId": [
      "2633","5710"
    ],
    "incrementId": 0,
    "incrementSize": 0
  }
}';
*/
?>